//import { Solar } from "./lunar"

function formatDate(date) {
  const year = date.getFullYear();
  // 确保月份为两位数
  const month = (date.getMonth() + 1).toString().padStart(2, '0'); 
  // 确保日期为两位数
  const day = date.getDate().toString().padStart(2, '0'); 
  return `${year}-${month}-${day}`;
}

function formatDateToZ(dateStr) {
  var year = dateStr.slice(0, 4);
  var month = parseInt(dateStr.slice(5, 7));
  var day = parseInt(dateStr.slice(8, 10));
  return year + '年' + month + '月' + day + '日';
}

function getSexs() {
  return ["未知", "男", "女"]
}

function getSexName(code) {
  return getSexs()[code]
}

function getMarrys() {
  return ["未知", "是", "否"]
}
function getMarryName(code) {
  return getMarrys()[code]
}

//function countResult(y, m, d) {
//  let data = [
//      {num: 4, t1: '甲', t2: '土+', t3: '脾、肾、肝'},
//      {num: 5, t1: '乙', t2: '金-', t3: '肺、肝、心'},
//      {num: 6, t1: '丙', t2: '水+', t3: '肾、心、脾'},
//      {num: 7, t1: '丁', t2: '木-', t3: '肝、脾、肺'},
//      {num: 8, t1: '戊', t2: '火+', t3: '心、肺、肾'},
//      {num: 9, t1: '己', t2: '土-', t3: '脾、肾、肝'},
//      {num: 0, t1: '庚', t2: '金+', t3: '肺、肝、心'},
//      {num: 1, t1: '辛', t2: '水-', t3: '肾、心、脾'},
//      {num: 2, t1: '壬', t2: '木+', t3: '肝、脾、肺'},
//      {num: 3, t1: '癸', t2: '火-', t3: '心、肺、肾'}
//  ];
//  let solar = Solar.fromYmd(y, m, d);
//  for (let i = 0; i < data.length; i++) {
//      if (solar.getLunar().getYearGan() == data[i].t1) {
//          return data[i].t3;
//      }
//  }
//}

/**
 * 获取数组中非空值的数量
 * @param {*} arr 
 */
function getArrNotNullLength(arr) {
  return arr&&arr.filter(item => item !== null && item != undefined).length||0
}

/**
 * 字段默认值
 * @param {字段值} value 
 * @param {默认值} defaultValue 
 */
function greet(value, defaultValue) {
  return value !== undefined && value !== null ? value : defaultValue
}


module.exports = {
  nowDate: formatDate(new Date()),
  formatDate: formatDate,
  formatDateToZ: formatDateToZ,
  getSexName: getSexName,
  getMarryName: getMarryName,
  // countResult: countResult,
  getArrNotNullLength: getArrNotNullLength,
  greet: greet
}
